package com.demo.ObjectInputStream_;


import com.demo.ObjectOutputStream_.Dog;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * @author gy
 * @date 2022/4/5
 */
public class ObjectInputStream01 {
    public static void main(String[] args) {
        String filePath = "f:\\20220403\\ObjectOutputStream01.xyz";
        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(new FileInputStream(filePath));

//            oos.writeInt(100);
//            oos.writeBoolean(true);
//            oos.writeChar('a');
//            oos.writeDouble(1.00);
//            oos.writeUTF("hello,ObjectOutputStream01");

//            oos.writeObject(new Dog("大黄","10"));
            ois.readInt();
            ois.readBoolean();
            ois.readChar();
            ois.readDouble();
            ois.readUTF();

            try {
                Object dog = ois.readObject();
                System.out.println("运行类型:"+ dog.getClass());
                System.out.println("dog 信息"+ dog.toString());
                Dog dog1 = (Dog)dog;
                dog1.setAge("3");

            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            System.out.println("反 序列化完成------------成功的将 数据类型 和 数据 值 从自定义的文件中，取出来");

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (ois != null) {
                    ois.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
